package arithmetic.sort;

/**
 *
 * 冒泡排序
 */
public class MaopaoSort {
    private static int[] nums = {6,2,6,5,1,2};

    public static void main(String[] args) {

        //思路：先对数组排序，排序后两两一组，分别取最小的累加得到结果
        //即:排序后下标为0数的元素之和
        //冒泡排序：双层循环
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if (nums[i] > nums[j + 1]) {
                    int temp = nums[i];
                    nums[i] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
        }

        //偶数下标累加得到最终值
        int sum = 0;
        for (int k = 0; k < nums.length - 1; k++) {
            if (k % 2 == 0) {
                sum += nums[k];
            }
        }
        System.out.println(sum);
    }
}
